<?php
namespace App\Validator\User;

use App\Exception\HttpException;
use Swoft\Validator\Contract\ValidatorInterface;
use Swoft\Validator\Annotation\Mapping\Validator;

/**
 * Class UserNameValidator
 * @Validator(name="UserNameValidator")
 * @package App\Validator\User
 */
class UserNameValidator implements ValidatorInterface
{

    /**
     * @param array $data
     * @param array $params
     * @return array
     * @throws HttpException
     */
    public function validate(array $data, array $params): array
    {
        if (in_array($data['username'], ['admin', 'kevip'])){
            return $data;
        }
        throw new HttpException('当前账号没有权限');
    }
}
